#ifndef __VALVE_MODULE_H__
#define __VALVE_MODULE_H__

#include "common.h"
#include "global_config.h"

/* Stepper motor control pins */
#define VALVE_COIL_A1_PIN GET_PIN(B, 4)
#define VALVE_COIL_A2_PIN GET_PIN(B, 5)
#define VALVE_COIL_B1_PIN GET_PIN(B, 6)
#define VALVE_COIL_B2_PIN GET_PIN(B, 7)

/* Valve control commands */
typedef enum {
    VALVE_CMD_MOVE_ABSOLUTE = 1,
    VALVE_CMD_MOVE_RELATIVE,
    VALVE_CMD_STOP,
    VALVE_CMD_HOME,
    VALVE_CMD_SET_POSITION
} valve_cmd_t;

/* Valve message data structures */
typedef struct {
    uint32_t target_step;
    uint32_t speed;  /* steps per second */
} valve_move_absolute_t;

typedef struct {
    int32_t steps;
    uint32_t speed;
} valve_move_relative_t;

/* Function declarations */
rt_err_t valve_module_init(void);
void valve_thread_entry(void *parameter);
rt_err_t valve_move_absolute(uint32_t target_step, uint32_t speed);
rt_err_t valve_move_relative(int32_t steps, uint32_t speed);
rt_err_t valve_stop(void);
rt_err_t valve_home(void);
float valve_get_position_percent(void);
uint32_t valve_get_current_step(void);
rt_bool_t valve_is_moving(void);

/* External configuration access */
extern valve_config_t *valve_get_config(void);

#endif /* __VALVE_MODULE_H__ */